<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>MODULE_IMAGE:  Fichier source de /home/radius/Documents/Rachid_Licence/LIF7/LIF7_TD1/module-image/src/Image.c</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<!-- Généré par Doxygen 1.6.1 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="main.html"><span>Page&nbsp;principale</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Fichiers</span></a></li>
      <li><a href="dirs.html"><span>Répertoires</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>Liste&nbsp;des&nbsp;fichiers</span></a></li>
      <li><a href="globals.html"><span>Membres&nbsp;de&nbsp;fichier</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="dir_53790bda95882cd03745840c1cece42e.html">src</a>
  </div>
</div>
<div class="contents">
<h1>Image.c</h1><a href="_image_8c.html">Aller à la documentation de ce fichier.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00008"></a>00008 <span class="preprocessor">#include &quot;<a class="code" href="_image_8h.html" title="Fichier d&amp;#39;entête du module Image.">Image.h</a>&quot;</span>
<a name="l00009"></a>00009 <span class="preprocessor">#include &quot;<a class="code" href="_pixel_8h.html" title="Fichier d&amp;#39;entête du module Pixel.">Pixel.h</a>&quot;</span>
<a name="l00010"></a>00010 
<a name="l00011"></a>00011 
<a name="l00012"></a>00012 
<a name="l00013"></a>00013 <span class="comment">/* ********************************************************************* */</span>
<a name="l00014"></a>00014 <span class="comment">/*                                                                       */</span>
<a name="l00015"></a>00015 <span class="comment">/*                 Fonctions relatives aux images                        */</span>
<a name="l00016"></a>00016 <span class="comment">/*                                                                       */</span>
<a name="l00017"></a>00017 <span class="comment">/* ********************************************************************* */</span>
<a name="l00018"></a><a class="code" href="_image_8h.html#a6edbdf3bfe3beb4e44246a6c7985055c">00018</a> <span class="keywordtype">void</span> <a class="code" href="_image_8c.html#a6edbdf3bfe3beb4e44246a6c7985055c" title="Initialise une image.">imInit</a> ( <a class="code" href="structs_image.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Image</a> *im, <span class="keyword">const</span> <span class="keywordtype">int</span> dimx, <span class="keyword">const</span> <span class="keywordtype">int</span> dimy)
<a name="l00019"></a>00019 {
<a name="l00020"></a>00020         assert(im != NULL) ;
<a name="l00021"></a>00021         assert(dimx &gt; 0) ;
<a name="l00022"></a>00022         assert(dimy &gt; 0) ;
<a name="l00023"></a>00023 
<a name="l00024"></a>00024         im-&gt;<a class="code" href="structs_image.html#adb2d38c3505ca0be7cb014f64a302cbe">dimx</a> = dimx ;
<a name="l00025"></a>00025         im-&gt;<a class="code" href="structs_image.html#a14c6823faa298b6c3d0767bd9ffaa769">dimy</a> = dimy ;
<a name="l00026"></a>00026         im-&gt;<a class="code" href="structs_image.html#a6951df3303ff6144e7786fe41b056082">pix</a> = (<a class="code" href="struct_pixel.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Pixel</a> *) malloc(dimx*dimy*<span class="keyword">sizeof</span>(<a class="code" href="struct_pixel.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Pixel</a>)) ;
<a name="l00027"></a>00027 }
<a name="l00028"></a>00028 
<a name="l00029"></a><a class="code" href="_image_8h.html#a5931290abc22d365ae351381c594613f">00029</a> <span class="keywordtype">void</span> <a class="code" href="_image_8c.html#a5931290abc22d365ae351381c594613f" title="Libère une image de la mémoire.">imLibere</a> (<a class="code" href="structs_image.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Image</a> *im)
<a name="l00030"></a>00030 {
<a name="l00031"></a>00031     assert(im != NULL) ;
<a name="l00032"></a>00032     assert(im-&gt;<a class="code" href="structs_image.html#a6951df3303ff6144e7786fe41b056082">pix</a> != NULL) ;
<a name="l00033"></a>00033 
<a name="l00034"></a>00034     im-&gt;<a class="code" href="structs_image.html#adb2d38c3505ca0be7cb014f64a302cbe">dimx</a> = 0 ;
<a name="l00035"></a>00035     im-&gt;<a class="code" href="structs_image.html#a14c6823faa298b6c3d0767bd9ffaa769">dimy</a> = 0 ;
<a name="l00036"></a>00036     free(im-&gt;<a class="code" href="structs_image.html#a6951df3303ff6144e7786fe41b056082">pix</a>);
<a name="l00037"></a>00037     im-&gt;<a class="code" href="structs_image.html#a6951df3303ff6144e7786fe41b056082">pix</a> = NULL ;
<a name="l00038"></a>00038 
<a name="l00039"></a>00039 }
<a name="l00040"></a>00040 
<a name="l00041"></a><a class="code" href="_image_8h.html#acd1b5e5f7a7fa80087a1e53bfa4da49d">00041</a> <a class="code" href="structs_image.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Image</a> * <a class="code" href="_image_8c.html#a13ab11befc99f60ea0a5255e22f7f2be" title="Alloue dans le tas une structure Image puis l&amp;#39;initialise avec imInit.">imCreer</a>(<span class="keyword">const</span> <span class="keywordtype">int</span> dimx, <span class="keyword">const</span> <span class="keywordtype">int</span> dimy)
<a name="l00042"></a>00042 {
<a name="l00043"></a>00043     <a class="code" href="structs_image.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Image</a> *pIm ;
<a name="l00044"></a>00044     pIm = (<a class="code" href="structs_image.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Image</a> *) malloc(<span class="keyword">sizeof</span>(<a class="code" href="structs_image.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Image</a>)) ;
<a name="l00045"></a>00045     <a class="code" href="_image_8c.html#a6edbdf3bfe3beb4e44246a6c7985055c" title="Initialise une image.">imInit</a>( pIm, dimx, dimy) ;
<a name="l00046"></a>00046 
<a name="l00047"></a>00047     <span class="keywordflow">return</span> pIm ;
<a name="l00048"></a>00048 }
<a name="l00049"></a>00049 
<a name="l00050"></a><a class="code" href="_image_8h.html#ae9d0336b23f7c615e57c4862714df90f">00050</a> <span class="keywordtype">void</span> <a class="code" href="_image_8c.html#ae9d0336b23f7c615e57c4862714df90f" title="Libere le tableau de pixel en appelant imLibere puis détruit la structure image...">imDetruire</a>(<a class="code" href="structs_image.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Image</a> *im)
<a name="l00051"></a>00051 {
<a name="l00052"></a>00052     assert(im != NULL);
<a name="l00053"></a>00053 
<a name="l00054"></a>00054     <a class="code" href="_image_8c.html#a5931290abc22d365ae351381c594613f" title="Libère une image de la mémoire.">imLibere</a>(im);
<a name="l00055"></a>00055     free(im);
<a name="l00056"></a>00056     im = NULL ;
<a name="l00057"></a>00057 }
<a name="l00058"></a>00058 
<a name="l00059"></a>00059 <span class="comment">/* ********************************************************************* */</span>
<a name="l00060"></a>00060 <span class="comment">/*                                                                       */</span>
<a name="l00061"></a>00061 <span class="comment">/*           Accesseurs et Mutateurs de la structure Image               */</span>
<a name="l00062"></a>00062 <span class="comment">/*                                                                       */</span>
<a name="l00063"></a>00063 <span class="comment">/* ********************************************************************* */</span>
<a name="l00064"></a>00064 
<a name="l00065"></a><a class="code" href="_image_8h.html#a1cb04a46ed83be9a0c49b3b884c91d62">00065</a> <a class="code" href="struct_pixel.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Pixel</a> <a class="code" href="_image_8c.html#a1cb04a46ed83be9a0c49b3b884c91d62" title="Récupère le pixel de coordonnée (x,y) en vérifiant leur validité.">getPix</a>(<span class="keyword">const</span> <a class="code" href="structs_image.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Image</a> *im, <span class="keyword">const</span> <span class="keywordtype">int</span> x, <span class="keyword">const</span> <span class="keywordtype">int</span> y)
<a name="l00066"></a>00066 {
<a name="l00067"></a>00067 
<a name="l00068"></a>00068     assert(im != NULL) ;
<a name="l00069"></a>00069     assert(x &lt; im-&gt;dimx) ;
<a name="l00070"></a>00070     assert(y &lt; im-&gt;dimy) ;
<a name="l00071"></a>00071 
<a name="l00072"></a>00072     <span class="keywordflow">return</span> im-&gt;<a class="code" href="structs_image.html#a6951df3303ff6144e7786fe41b056082">pix</a>[y*im-&gt;<a class="code" href="structs_image.html#adb2d38c3505ca0be7cb014f64a302cbe">dimx</a>+x] ;
<a name="l00073"></a>00073 }
<a name="l00074"></a>00074 
<a name="l00075"></a><a class="code" href="_image_8h.html#ad239628e88372f488e18848112517521">00075</a> <span class="keywordtype">void</span> <a class="code" href="_image_8c.html#ad239628e88372f488e18848112517521" title="Modifie le pixel de coordonnée (x,y).">setPix</a>(<a class="code" href="structs_image.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Image</a> * im, <span class="keyword">const</span> <span class="keywordtype">int</span> x, <span class="keyword">const</span> <span class="keywordtype">int</span> y, <span class="keyword">const</span> <a class="code" href="struct_pixel.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Pixel</a> * couleur)
<a name="l00076"></a>00076 {
<a name="l00077"></a>00077 
<a name="l00078"></a>00078     assert(im != NULL) ;
<a name="l00079"></a>00079     assert(x &lt; im-&gt;dimx) ;
<a name="l00080"></a>00080     assert(y &lt; im-&gt;dimy) ;
<a name="l00081"></a>00081 
<a name="l00082"></a>00082     im-&gt;<a class="code" href="structs_image.html#a6951df3303ff6144e7786fe41b056082">pix</a>[y*im-&gt;<a class="code" href="structs_image.html#adb2d38c3505ca0be7cb014f64a302cbe">dimx</a>+x] = (*couleur) ;
<a name="l00083"></a>00083 
<a name="l00084"></a>00084 
<a name="l00085"></a>00085 }
<a name="l00086"></a>00086 
<a name="l00087"></a>00087 <span class="comment">/* ********************************************************************* */</span>
<a name="l00088"></a>00088 <span class="comment">/*                                                                       */</span>
<a name="l00089"></a>00089 <span class="comment">/*                 Fonctions relatives aux rectangles                    */</span>
<a name="l00090"></a>00090 <span class="comment">/*                                                                       */</span>
<a name="l00091"></a>00091 <span class="comment">/* ********************************************************************* */</span>
<a name="l00092"></a>00092 
<a name="l00093"></a><a class="code" href="_image_8h.html#aae7e2d32a1d4c4516a818d8a473c0a86">00093</a> <span class="keywordtype">void</span> <a class="code" href="_image_8c.html#aae7e2d32a1d4c4516a818d8a473c0a86" title="Dessine un rectangle de couleur dans l&amp;#39;image en utilisant setPix.">imDessineRectangle</a>(<a class="code" href="structs_image.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Image</a> *im, <span class="keyword">const</span> <span class="keywordtype">int</span> Xmin, <span class="keyword">const</span> <span class="keywordtype">int</span> Ymin, <span class="keyword">const</span> <span class="keywordtype">int</span> Xmax, <span class="keyword">const</span> <span class="keywordtype">int</span> Ymax, <span class="keyword">const</span> <a class="code" href="struct_pixel.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Pixel</a> * couleur)
<a name="l00094"></a>00094 {
<a name="l00095"></a>00095     <span class="keywordtype">int</span> i, j ;
<a name="l00096"></a>00096     assert(im != NULL) ;
<a name="l00097"></a>00097     assert(Xmin &lt;= im-&gt;dimx) ;
<a name="l00098"></a>00098     assert(Xmin &gt;=0) ;
<a name="l00099"></a>00099     assert(Ymin &lt;= im-&gt;dimy) ;
<a name="l00100"></a>00100     assert(Ymin &gt;=0) ;
<a name="l00101"></a>00101     assert(Xmax &lt;= im-&gt;dimx) ;
<a name="l00102"></a>00102     assert(Xmax &gt;= Xmin) ;
<a name="l00103"></a>00103     assert(Ymax &lt;= im-&gt;dimy) ;
<a name="l00104"></a>00104     assert(Ymax &gt;= Ymin) ;
<a name="l00105"></a>00105 
<a name="l00106"></a>00106     <span class="keywordflow">for</span>(i=Xmin ; i&lt;Xmax ; i++){
<a name="l00107"></a>00107         <span class="keywordflow">for</span>(j=Ymin ; j&lt;Ymax ; j++){
<a name="l00108"></a>00108             <a class="code" href="_image_8c.html#ad239628e88372f488e18848112517521" title="Modifie le pixel de coordonnée (x,y).">setPix</a>(im, i, j, couleur) ;
<a name="l00109"></a>00109         }
<a name="l00110"></a>00110     }
<a name="l00111"></a>00111 }
<a name="l00112"></a>00112 
<a name="l00113"></a><a class="code" href="_image_8h.html#aa04f50f4353fee39ec6cfd7201ab0367">00113</a> <span class="keywordtype">void</span> <a class="code" href="_image_8c.html#aa04f50f4353fee39ec6cfd7201ab0367" title="Efface l&amp;#39;image en appelant imDessineRectangle avec le bon rectangle.">imEffacer</a>(<a class="code" href="structs_image.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Image</a> *im, <span class="keyword">const</span> <a class="code" href="struct_pixel.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Pixel</a> * couleur)
<a name="l00114"></a>00114 {
<a name="l00115"></a>00115 
<a name="l00116"></a>00116     <span class="keywordtype">int</span> Xmin = 0 ;
<a name="l00117"></a>00117     <span class="keywordtype">int</span> Ymin = 0 ;
<a name="l00118"></a>00118     <span class="keywordtype">int</span> Xmax = im-&gt;<a class="code" href="structs_image.html#adb2d38c3505ca0be7cb014f64a302cbe">dimx</a> ;
<a name="l00119"></a>00119     <span class="keywordtype">int</span> Ymax = im-&gt;<a class="code" href="structs_image.html#a14c6823faa298b6c3d0767bd9ffaa769">dimy</a> ;
<a name="l00120"></a>00120 
<a name="l00121"></a>00121     assert(im != NULL) ;
<a name="l00122"></a>00122 
<a name="l00123"></a>00123     <a class="code" href="_image_8c.html#aae7e2d32a1d4c4516a818d8a473c0a86" title="Dessine un rectangle de couleur dans l&amp;#39;image en utilisant setPix.">imDessineRectangle</a>(im, Xmin, Ymin, Xmax, Ymax, couleur) ;
<a name="l00124"></a>00124 }
<a name="l00125"></a>00125 
<a name="l00126"></a>00126 <span class="comment">/* ********************************************************************* */</span>
<a name="l00127"></a>00127 <span class="comment">/*                                                                       */</span>
<a name="l00128"></a>00128 <span class="comment">/*             Fonctions relatives aux gestiond&apos;images                   */</span>
<a name="l00129"></a>00129 <span class="comment">/*                                                                       */</span>
<a name="l00130"></a>00130 <span class="comment">/* ********************************************************************* */</span>
<a name="l00131"></a>00131 
<a name="l00132"></a><a class="code" href="_image_8h.html#a20b9ad35b6db7bd09d7452574d04dd50">00132</a> <span class="keywordtype">void</span> <a class="code" href="_image_8c.html#a20b9ad35b6db7bd09d7452574d04dd50" title="sauvegarde une image au format .ppm.">imSauver</a>(<span class="keyword">const</span> <a class="code" href="structs_image.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Image</a> *pIm, <span class="keyword">const</span> <span class="keywordtype">char</span> filename[])
<a name="l00133"></a>00133 {
<a name="l00134"></a>00134     FILE* f;
<a name="l00135"></a>00135         <a class="code" href="struct_pixel.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Pixel</a> pix;
<a name="l00136"></a>00136         <span class="keywordtype">int</span> x,y;
<a name="l00137"></a>00137 
<a name="l00138"></a>00138     f = fopen(filename, <span class="stringliteral">&quot;w&quot;</span>);
<a name="l00139"></a>00139     <span class="keywordflow">if</span> (f==NULL)
<a name="l00140"></a>00140     {
<a name="l00141"></a>00141         printf(<span class="stringliteral">&quot;Erreur lors de l&apos;ouverture de %s\n&quot;</span>, filename);
<a name="l00142"></a>00142         assert( f );
<a name="l00143"></a>00143     }
<a name="l00144"></a>00144     fprintf( f , <span class="stringliteral">&quot;P3\n&quot;</span>);                           <span class="comment">/* P3 = ascii avec 3 composantes RVB */</span>
<a name="l00145"></a>00145     fprintf( f , <span class="stringliteral">&quot;%d %d\n&quot;</span>, pIm-&gt;<a class="code" href="structs_image.html#adb2d38c3505ca0be7cb014f64a302cbe">dimx</a>, pIm-&gt;<a class="code" href="structs_image.html#a14c6823faa298b6c3d0767bd9ffaa769">dimy</a>);      <span class="comment">/* dimension de l&apos;image */</span>
<a name="l00146"></a>00146     fprintf( f , <span class="stringliteral">&quot;255\n&quot;</span>);                          <span class="comment">/* chaque composante est comprise entre 0 et 255*/</span>
<a name="l00147"></a>00147 
<a name="l00148"></a>00148     <span class="keywordflow">for</span>(y=0;y&lt;pIm-&gt;<a class="code" href="structs_image.html#a14c6823faa298b6c3d0767bd9ffaa769">dimy</a>;++y)
<a name="l00149"></a>00149         <span class="keywordflow">for</span>(x=0;x&lt;pIm-&gt;<a class="code" href="structs_image.html#adb2d38c3505ca0be7cb014f64a302cbe">dimx</a>;++x)
<a name="l00150"></a>00150         {
<a name="l00151"></a>00151             pix = <a class="code" href="_image_8c.html#a1cb04a46ed83be9a0c49b3b884c91d62" title="Récupère le pixel de coordonnée (x,y) en vérifiant leur validité.">getPix</a>(pIm,x,y);
<a name="l00152"></a>00152             fprintf(f, <span class="stringliteral">&quot;%d %d %d  &quot;</span>, pix.r, pix.v, pix.b);
<a name="l00153"></a>00153         }
<a name="l00154"></a>00154     printf(<span class="stringliteral">&quot;Sauvegarde de l&apos;image %s ...OK\n&quot;</span>, filename);
<a name="l00155"></a>00155     fclose(f);
<a name="l00156"></a>00156 }
<a name="l00157"></a>00157 
<a name="l00158"></a><a class="code" href="_image_8h.html#a0a1f0b9be4b910e1cfc2648cfa9e38fd">00158</a> <span class="keywordtype">void</span> <a class="code" href="_image_8c.html#a0a1f0b9be4b910e1cfc2648cfa9e38fd" title="Ouvre une image au format .ppm.">imOuvrir</a>(<a class="code" href="structs_image.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Image</a> *pIm, <span class="keyword">const</span> <span class="keywordtype">char</span> filename[])
<a name="l00159"></a>00159 {
<a name="l00160"></a>00160     FILE* f;
<a name="l00161"></a>00161         <a class="code" href="struct_pixel.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Pixel</a> pix;
<a name="l00162"></a>00162         <span class="keywordtype">int</span> x, y, dimx, dimy;
<a name="l00163"></a>00163 
<a name="l00164"></a>00164     f = fopen(filename, <span class="stringliteral">&quot;r&quot;</span>);
<a name="l00165"></a>00165     <span class="keywordflow">if</span> (f==NULL)
<a name="l00166"></a>00166     {
<a name="l00167"></a>00167         printf(<span class="stringliteral">&quot;Erreur lors de l&apos;ouverture de %s\n&quot;</span>, filename);
<a name="l00168"></a>00168         assert( f );
<a name="l00169"></a>00169     }
<a name="l00170"></a>00170 
<a name="l00171"></a>00171     assert( fscanf( f , <span class="stringliteral">&quot;P3\n%d %d\n255\n&quot;</span>, &amp;dimx, &amp;dimy) ==2 );
<a name="l00172"></a>00172     <a class="code" href="_image_8c.html#a6edbdf3bfe3beb4e44246a6c7985055c" title="Initialise une image.">imInit</a>( pIm, dimx, dimy);
<a name="l00173"></a>00173 
<a name="l00174"></a>00174     <span class="keywordflow">for</span>(y=0;y&lt;pIm-&gt;<a class="code" href="structs_image.html#a14c6823faa298b6c3d0767bd9ffaa769">dimy</a>;++y)
<a name="l00175"></a>00175         <span class="keywordflow">for</span>(x=0;x&lt;pIm-&gt;<a class="code" href="structs_image.html#adb2d38c3505ca0be7cb014f64a302cbe">dimx</a>;++x)
<a name="l00176"></a>00176         {
<a name="l00177"></a>00177             assert( fscanf(f, <span class="stringliteral">&quot;%d %d %d  &quot;</span>, &amp;pix.r, &amp;pix.v, &amp;pix.b)==3 );
<a name="l00178"></a>00178                         <a class="code" href="_image_8c.html#ad239628e88372f488e18848112517521" title="Modifie le pixel de coordonnée (x,y).">setPix</a>(pIm,x,y,&amp;pix);
<a name="l00179"></a>00179         }
<a name="l00180"></a>00180     fclose(f);
<a name="l00181"></a>00181     printf(<span class="stringliteral">&quot;Lecture de l&apos;image %s ...OK\n&quot;</span>, filename);
<a name="l00182"></a>00182 }
<a name="l00183"></a>00183 
<a name="l00184"></a><a class="code" href="_image_8h.html#afadf8ab43119d304c72e201d0d95164d">00184</a> <span class="keywordtype">void</span> <a class="code" href="_image_8c.html#afadf8ab43119d304c72e201d0d95164d" title="sauvegarde une image au format .ppm.">imPrintf</a>(<span class="keyword">const</span> <a class="code" href="structs_image.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Image</a> *pIm)
<a name="l00185"></a>00185 {
<a name="l00186"></a>00186         <span class="keywordtype">int</span> x,y;
<a name="l00187"></a>00187         <a class="code" href="struct_pixel.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Pixel</a> pix;
<a name="l00188"></a>00188 
<a name="l00189"></a>00189     printf( <span class="stringliteral">&quot;%d %d\n&quot;</span>, pIm-&gt;<a class="code" href="structs_image.html#adb2d38c3505ca0be7cb014f64a302cbe">dimx</a>, pIm-&gt;<a class="code" href="structs_image.html#a14c6823faa298b6c3d0767bd9ffaa769">dimy</a>);      <span class="comment">/* dimension de l&apos;image */</span>
<a name="l00190"></a>00190 
<a name="l00191"></a>00191     <span class="keywordflow">for</span>(y=0;y&lt;pIm-&gt;<a class="code" href="structs_image.html#a14c6823faa298b6c3d0767bd9ffaa769">dimy</a>;++y)
<a name="l00192"></a>00192     {
<a name="l00193"></a>00193         <span class="keywordflow">for</span>(x=0;x&lt;pIm-&gt;<a class="code" href="structs_image.html#adb2d38c3505ca0be7cb014f64a302cbe">dimx</a>;++x)
<a name="l00194"></a>00194         {
<a name="l00195"></a>00195             pix = <a class="code" href="_image_8c.html#a1cb04a46ed83be9a0c49b3b884c91d62" title="Récupère le pixel de coordonnée (x,y) en vérifiant leur validité.">getPix</a>(pIm,x,y);
<a name="l00196"></a>00196             printf(<span class="stringliteral">&quot;%d %d %d  &quot;</span>, pix.r, pix.v, pix.b);
<a name="l00197"></a>00197         }
<a name="l00198"></a>00198         printf(<span class="stringliteral">&quot;\n&quot;</span>);
<a name="l00199"></a>00199     }
<a name="l00200"></a>00200 }
<a name="l00201"></a>00201 
<a name="l00202"></a>00202 <span class="comment">/* ********************************************************************* */</span>
<a name="l00203"></a>00203 <span class="comment">/*                                                                       */</span>
<a name="l00204"></a>00204 <span class="comment">/*                           Test de regression                          */</span>
<a name="l00205"></a>00205 <span class="comment">/*                                                                       */</span>
<a name="l00206"></a>00206 <span class="comment">/* ********************************************************************* */</span>
<a name="l00207"></a>00207 
<a name="l00208"></a><a class="code" href="_image_8h.html#a4fdd00deba298ac07e0636bace7a0e61">00208</a> <span class="keywordtype">void</span> <a class="code" href="_image_8c.html#a4fdd00deba298ac07e0636bace7a0e61" title="Teste toutes les fonctions du module image.h.">ImRegressionTest</a>(<span class="keywordtype">void</span>)
<a name="l00209"></a>00209 {
<a name="l00210"></a>00210         <a class="code" href="structs_image.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Image</a> im ;
<a name="l00211"></a>00211         <a class="code" href="structs_image.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Image</a> *im2;
<a name="l00212"></a>00212 
<a name="l00213"></a>00213         <a class="code" href="structs_image.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Image</a> **im3;
<a name="l00214"></a>00214         <span class="keywordtype">int</span> i ;
<a name="l00215"></a>00215         <a class="code" href="struct_pixel.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Pixel</a> pix = {255, 255, 255};
<a name="l00216"></a>00216 
<a name="l00217"></a>00217         printf(<span class="stringliteral">&quot;TEST DE REGRESSION DU MODULE IMAGE : \n&quot;</span>) ;
<a name="l00218"></a>00218 
<a name="l00219"></a>00219         <span class="comment">/* Test de la fonction imInit */</span>
<a name="l00220"></a>00220 
<a name="l00221"></a>00221         printf(<span class="stringliteral">&quot;\nTest de imInit pour une image de petite taille : &quot;</span>);
<a name="l00222"></a>00222         <a class="code" href="_image_8c.html#a6edbdf3bfe3beb4e44246a6c7985055c" title="Initialise une image.">imInit</a>(&amp; im, 1, 1 ) ;
<a name="l00223"></a>00223         printf(<span class="stringliteral">&quot;ok.\n&quot;</span>) ;
<a name="l00224"></a>00224 
<a name="l00225"></a>00225         printf(<span class="stringliteral">&quot;Test des accesseurs : &quot;</span>);
<a name="l00226"></a>00226         assert(((im.<a class="code" href="structs_image.html#adb2d38c3505ca0be7cb014f64a302cbe">dimx</a>) == 1) &amp;&amp; ((im.<a class="code" href="structs_image.html#a14c6823faa298b6c3d0767bd9ffaa769">dimy</a>) == 1) &amp;&amp; (im.<a class="code" href="structs_image.html#a6951df3303ff6144e7786fe41b056082">pix</a> != NULL)) ;
<a name="l00227"></a>00227         printf(<span class="stringliteral">&quot;ok.\n&quot;</span>) ;
<a name="l00228"></a>00228 
<a name="l00229"></a>00229         <a class="code" href="_image_8c.html#a5931290abc22d365ae351381c594613f" title="Libère une image de la mémoire.">imLibere</a>(&amp;im);
<a name="l00230"></a>00230 
<a name="l00231"></a>00231         printf(<span class="stringliteral">&quot;Test de imInit pour une image de taille moyenne : &quot;</span>);
<a name="l00232"></a>00232         <a class="code" href="_image_8c.html#a6edbdf3bfe3beb4e44246a6c7985055c" title="Initialise une image.">imInit</a>(&amp; im, 50, 50 ) ;
<a name="l00233"></a>00233         printf(<span class="stringliteral">&quot;ok.\n&quot;</span>) ;
<a name="l00234"></a>00234 
<a name="l00235"></a>00235         printf(<span class="stringliteral">&quot;Test des accesseurs : &quot;</span>);
<a name="l00236"></a>00236         
<a name="l00237"></a>00237         assert(((im.<a class="code" href="structs_image.html#adb2d38c3505ca0be7cb014f64a302cbe">dimx</a>) == 50) &amp;&amp; ((im.<a class="code" href="structs_image.html#a14c6823faa298b6c3d0767bd9ffaa769">dimy</a>) == 50) &amp;&amp; (im.<a class="code" href="structs_image.html#a6951df3303ff6144e7786fe41b056082">pix</a> != NULL)) ;
<a name="l00238"></a>00238         
<a name="l00239"></a>00239         printf(<span class="stringliteral">&quot;ok.\n&quot;</span>) ;
<a name="l00240"></a>00240 
<a name="l00241"></a>00241         <a class="code" href="_image_8c.html#a5931290abc22d365ae351381c594613f" title="Libère une image de la mémoire.">imLibere</a>(&amp;im);
<a name="l00242"></a>00242         
<a name="l00243"></a>00243         printf(<span class="stringliteral">&quot;Test de imInit pour une image de grande taille : &quot;</span>);
<a name="l00244"></a>00244         <a class="code" href="_image_8c.html#a6edbdf3bfe3beb4e44246a6c7985055c" title="Initialise une image.">imInit</a>(&amp; im, 4096, 4096 ) ;
<a name="l00245"></a>00245         printf(<span class="stringliteral">&quot;ok.\n&quot;</span>) ;
<a name="l00246"></a>00246 
<a name="l00247"></a>00247         printf(<span class="stringliteral">&quot;Test des accesseurs : &quot;</span>);
<a name="l00248"></a>00248         assert(((im.<a class="code" href="structs_image.html#adb2d38c3505ca0be7cb014f64a302cbe">dimx</a>) == 4096) &amp;&amp; ((im.<a class="code" href="structs_image.html#a14c6823faa298b6c3d0767bd9ffaa769">dimy</a>) == 4096) &amp;&amp; (im.<a class="code" href="structs_image.html#a6951df3303ff6144e7786fe41b056082">pix</a> != NULL)) ;
<a name="l00249"></a>00249         printf(<span class="stringliteral">&quot;ok.\n&quot;</span>) ;
<a name="l00250"></a>00250         
<a name="l00251"></a>00251         <span class="comment">/* Test de la fonction imlibere */</span>
<a name="l00252"></a>00252         
<a name="l00253"></a>00253         printf(<span class="stringliteral">&quot;\nAffichage des dimenssions de l&apos;image avant libération: \n&quot;</span>);
<a name="l00254"></a>00254         printf(<span class="stringliteral">&quot;dimx est égale à : %d\n&quot;</span>,im.<a class="code" href="structs_image.html#adb2d38c3505ca0be7cb014f64a302cbe">dimx</a>) ;
<a name="l00255"></a>00255         printf(<span class="stringliteral">&quot;dimY est égale à : %d\n&quot;</span>,im.<a class="code" href="structs_image.html#a14c6823faa298b6c3d0767bd9ffaa769">dimy</a>) ;
<a name="l00256"></a>00256 
<a name="l00257"></a>00257         printf(<span class="stringliteral">&quot;\nTest de la fonction imLibere : &quot;</span>);
<a name="l00258"></a>00258         <a class="code" href="_image_8c.html#a5931290abc22d365ae351381c594613f" title="Libère une image de la mémoire.">imLibere</a>(&amp; im) ;
<a name="l00259"></a>00259         assert((im.<a class="code" href="structs_image.html#adb2d38c3505ca0be7cb014f64a302cbe">dimx</a> == 0) &amp;&amp; (im.<a class="code" href="structs_image.html#a14c6823faa298b6c3d0767bd9ffaa769">dimy</a> == 0) &amp;&amp; (im.<a class="code" href="structs_image.html#a6951df3303ff6144e7786fe41b056082">pix</a> == NULL)) ;
<a name="l00260"></a>00260         printf(<span class="stringliteral">&quot;ok.\n&quot;</span>) ;
<a name="l00261"></a>00261         
<a name="l00262"></a>00262         printf(<span class="stringliteral">&quot;\nAffichage des dimenssions de l&apos;image après libération: \n&quot;</span>);
<a name="l00263"></a>00263         printf(<span class="stringliteral">&quot;dimx est égale à : %d\n&quot;</span>,im.<a class="code" href="structs_image.html#adb2d38c3505ca0be7cb014f64a302cbe">dimx</a>) ;
<a name="l00264"></a>00264         printf(<span class="stringliteral">&quot;dimY est égale à : %d\n&quot;</span>,im.<a class="code" href="structs_image.html#a14c6823faa298b6c3d0767bd9ffaa769">dimy</a>) ;
<a name="l00265"></a>00265         
<a name="l00266"></a>00266         <span class="comment">/* Test de la fonction imCreer */</span>
<a name="l00267"></a>00267         
<a name="l00268"></a>00268         printf(<span class="stringliteral">&quot;\nTest de la fonction imCreer : &quot;</span>) ;
<a name="l00269"></a>00269         im2 = <a class="code" href="_image_8c.html#a13ab11befc99f60ea0a5255e22f7f2be" title="Alloue dans le tas une structure Image puis l&amp;#39;initialise avec imInit.">imCreer</a>(50,50) ;
<a name="l00270"></a>00270         assert((im2 != NULL) &amp;&amp; (im2-&gt;<a class="code" href="structs_image.html#adb2d38c3505ca0be7cb014f64a302cbe">dimx</a> == 50) &amp;&amp; (im2-&gt;<a class="code" href="structs_image.html#a14c6823faa298b6c3d0767bd9ffaa769">dimy</a> == 50)) ;
<a name="l00271"></a>00271         printf(<span class="stringliteral">&quot;ok. \n&quot;</span>) ;
<a name="l00272"></a>00272 
<a name="l00273"></a>00273         printf(<span class="stringliteral">&quot;dimx : %d\n&quot;</span>, im2-&gt;<a class="code" href="structs_image.html#adb2d38c3505ca0be7cb014f64a302cbe">dimx</a>) ;
<a name="l00274"></a>00274         printf(<span class="stringliteral">&quot;dimy : %d\n&quot;</span>, im2-&gt;<a class="code" href="structs_image.html#a14c6823faa298b6c3d0767bd9ffaa769">dimy</a>) ;
<a name="l00275"></a>00275         
<a name="l00276"></a>00276         <span class="comment">/* Test de la fonction imDetruire */</span>
<a name="l00277"></a>00277         
<a name="l00278"></a>00278         printf(<span class="stringliteral">&quot;\nTest de la fonction imDetruire : &quot;</span>) ;
<a name="l00279"></a>00279 
<a name="l00280"></a>00280         <a class="code" href="_image_8c.html#ae9d0336b23f7c615e57c4862714df90f" title="Libere le tableau de pixel en appelant imLibere puis détruit la structure image...">imDetruire</a>(im2) ;
<a name="l00281"></a>00281 
<a name="l00282"></a>00282         printf(<span class="stringliteral">&quot;ok.\n&quot;</span>) ;
<a name="l00283"></a>00283 
<a name="l00284"></a>00284         <span class="comment">/* Traitement sur 100 images */</span>
<a name="l00285"></a>00285         printf(<span class="stringliteral">&quot;création d&apos;un tableau contenant 100 images :\n&quot;</span>) ;
<a name="l00286"></a>00286         printf(<span class="stringliteral">&quot;Allocation d&apos;un tableaux pour contenir les images : &quot;</span>) ;
<a name="l00287"></a>00287         im3 = (<a class="code" href="structs_image.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Image</a> **) malloc ( 100 * <span class="keyword">sizeof</span>(<a class="code" href="structs_image.html" title="Structure utilisée pour la gestion d&amp;#39;une image.">Image</a> *));
<a name="l00288"></a>00288         printf(<span class="stringliteral">&quot;ok.\n&quot;</span>) ;
<a name="l00289"></a>00289         printf(<span class="stringliteral">&quot;Création des images : &quot;</span>) ;
<a name="l00290"></a>00290         <span class="keywordflow">for</span>(i = 0; i &lt; 100; i++)
<a name="l00291"></a>00291           im3[i] = <a class="code" href="_image_8c.html#a13ab11befc99f60ea0a5255e22f7f2be" title="Alloue dans le tas une structure Image puis l&amp;#39;initialise avec imInit.">imCreer</a>(i+100, i+512);
<a name="l00292"></a>00292         printf(<span class="stringliteral">&quot;ok.\n&quot;</span>) ;
<a name="l00293"></a>00293         printf(<span class="stringliteral">&quot;Remplissage des images avec un pixel de couleur: &quot;</span>) ;
<a name="l00294"></a>00294         <span class="keywordflow">for</span>(i = 0; i &lt; 100; i++)
<a name="l00295"></a>00295           <a class="code" href="_image_8c.html#aa04f50f4353fee39ec6cfd7201ab0367" title="Efface l&amp;#39;image en appelant imDessineRectangle avec le bon rectangle.">imEffacer</a>(im3[i], &amp;pix);
<a name="l00296"></a>00296         printf(<span class="stringliteral">&quot;ok.\n&quot;</span>) ;
<a name="l00297"></a>00297         printf(<span class="stringliteral">&quot;Suppression des images : &quot;</span>) ;
<a name="l00298"></a>00298         <span class="keywordflow">for</span>(i = 0; i &lt; 100; i++)
<a name="l00299"></a>00299           <a class="code" href="_image_8c.html#ae9d0336b23f7c615e57c4862714df90f" title="Libere le tableau de pixel en appelant imLibere puis détruit la structure image...">imDetruire</a>(im3[i]);
<a name="l00300"></a>00300         printf(<span class="stringliteral">&quot;ok.\n&quot;</span>) ;
<a name="l00301"></a>00301         printf(<span class="stringliteral">&quot;Libération du tableau d&apos;image : &quot;</span>) ;
<a name="l00302"></a>00302         free(im3);
<a name="l00303"></a>00303         printf(<span class="stringliteral">&quot;ok.\n&quot;</span>) ;
<a name="l00304"></a>00304         printf(<span class="stringliteral">&quot;\nTEST DE REGRESSION DU MODULE IMAGE&quot;</span>) ;
<a name="l00305"></a>00305 }
</pre></div></div>
<hr size="1"/><address style="text-align: right;"><small>Généré le Fri Oct 21 20:06:53 2011 pour MODULE_IMAGE par&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
</body>
</html>
